package game.views;

import hx.utils.SoundManager;
import game.modes.ModeManage;
import hx.utils.SceneManager;
import hx.display.UILoadScene;
import game.worlds.Game1V1BaseWorld;

using StringTools;

/**
 * 战斗准备界面，选择相关的界面内容
 */
@:build(hx.macro.UIBuilder.build("assets/views/FightReadyView.xml"))
class FightReadyView extends UILoadScene {
	override function onLoaded() {
		super.onLoaded();
		this.back.clickEvent = () -> {
			SceneManager.getInstance().backScene(true);
		}
		this.ok.clickEvent = () -> {
			// 设置参数
			var timeParam:String = time.selectedItem.value;
			ModeManage.currentReadyWorld.option.time = timeParam == "无限" ? -1 : Std.parseInt(timeParam);
			// 设置生命比例
			var hpScaleParam:String = this.hpScale.selectedItem.value;
			ModeManage.currentReadyWorld.option.hpScale = Std.parseFloat(hpScaleParam.replace("%", "")) / 100;
			// 设置气力值比例
			var effortScaleParam:String = this.effortScale.selectedItem.value;
			ModeManage.currentReadyWorld.option.effortScale = Std.parseFloat(effortScaleParam.replace("%", "")) / 100;
			// 设置角色AI
			var modeParam:String = mode.selectedItem.value;
			var world:Game1V1BaseWorld = cast ModeManage.currentReadyWorld;
			switch modeParam {
				case "1VS1":
					world.p1AiEnable = false;
					world.p2AiEnable = false;
				case "1VS电脑":
					world.p1AiEnable = false;
					world.p2AiEnable = true;
				case "电脑VS电脑":
					world.p1AiEnable = true;
					world.p2AiEnable = true;
			}
			// 进入地图选择模式
			SceneManager.getInstance().replaceScene(new MapSelectView());
			SoundManager.getInstance().playEffect("selected");
		}
	}
}
